import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class Enemy here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Enemy extends Actor
{
    /**
     * Act - do whatever the Enemy wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
        setRotation((int)playerDirection());
        move(1);
        checkDead();
    }    
    
    public double playerDirection()
    {
        int pX = ((City)getWorld()).getShooter().getX();
        int pY = ((City)getWorld()).getShooter().getY();
        double dX =  pX - this.getX();
        double dY =  pY - this.getY();
        if (pX != this.getX()){
            if (pX < this.getX()){
                return 180+180/3.14159265*Math.atan(dY/dX);
            }
            else if (pX > this.getX()){
                return 180/3.14159265*Math.atan(dY/dX);
            }
        }
        else if (this.getY() > (pY))
        {
            return 270;
        }
        return 90;
    }
    
    public void checkDead()
    {
        Bullet b = (Bullet)getOneIntersectingObject(Bullet.class);
        if (b != null)
        {
            getWorld().removeObject(b);
            getWorld().removeObject(this);
        }
    }
}
